package com.ebupt.myapp.service.impl;

import java.net.URI;

import org.apache.log4j.Logger;
import org.springframework.web.client.RestOperations;

import com.ebupt.myapp.service.CaiyinService;

public class CaiyinServiceImpl implements CaiyinService {

	protected Logger logger = Logger.getLogger(CaiyinServiceImpl.class);

	private String caiyinModSettingURL;
	private String caiyinGetSettingURL;

	private RestOperations caiyinRestTemplate;

	@Override
	public boolean modSetting(String phoneNumber, String content) {
		try {
			String resp = new String(caiyinRestTemplate.getForObject(
					URI.create(caiyinModSettingURL + "?phoneNumber="
							+ phoneNumber + "&content=" + content),
					byte[].class));
			logger.info(">>>>>>>>>>>>>" + resp);
			return true;
		} catch (Exception e) {
			throw new IllegalStateException(e);
		}
	}

	@Override
	public String getSetting(String phoneNumber) {
		try {
			String resp = new String(caiyinRestTemplate.getForObject(
					URI.create(caiyinModSettingURL + "?phoneNumber="
							+ phoneNumber), byte[].class));
			logger.info(">>>>>>>>>>>>>" + resp);
			return resp;
		} catch (Exception e) {
			throw new IllegalStateException(e);
		}
	}

	public String getCaiyinModSettingURL() {
		return caiyinModSettingURL;
	}

	public void setCaiyinModSettingURL(String caiyinModSettingURL) {
		this.caiyinModSettingURL = caiyinModSettingURL;
	}

	public String getCaiyinGetSettingURL() {
		return caiyinGetSettingURL;
	}

	public void setCaiyinGetSettingURL(String caiyinGetSettingURL) {
		this.caiyinGetSettingURL = caiyinGetSettingURL;
	}

	public RestOperations getCaiyinRestTemplate() {
		return caiyinRestTemplate;
	}

	public void setCaiyinRestTemplate(RestOperations caiyinRestTemplate) {
		this.caiyinRestTemplate = caiyinRestTemplate;
	}

}
